package com.css.fxfzmh.logInfo;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzmh.base.response.RestResponse;
import com.css.fxfzmh.logInfo.entity.SLog;
import com.css.fxfzmh.logInfo.entity.SLogParam;
import com.css.fxfzmh.zcpt.sys.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/05/15
 * @Description: LOG
 */
@RestController
@Slf4j
@RequestMapping("/log")
public class LogController {
    @Resource
    private SysLogService sysLogService;

    /**
     * 分页列表
     * @param param 参数
     * @return page
     */
    @GetMapping("/getPage")
    public RestResponse getPage(SLogParam param) {
        try {
            JSONObject data= sysLogService.getPage(param);
            return RestResponse.succeed(data);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            return RestResponse.fail(errormessage);
        }
    }

    /**
     * 添加日志
     * @param sLog 日志内容
     * @return
     */
    @PostMapping("/saveLogs")
    public RestResponse saveLogs(SLog sLog) {
        try {
            String data = sysLogService.saveLogs(sLog);
            return RestResponse.succeed(data);
        } catch (Exception e) {
            String errormessage = "添加失败";
            log.error(errormessage, e);
            return RestResponse.fail(errormessage);
        }
    }
}
